// -------------------------------------------------------------
// api: user.account.loginPassword.update
// time: 2020-07-18
// author: minner
// -------------------------------------------------------------
exports['user.account.loginPassword.update'] = {
    '1.0': function (args, session, callback) {
        if (!session.account_id) {
            return callback(12, null, '会话已失效');
        }
        if (1) {
            return callback(12, null, '本系统仅用于示例展示，已禁止修改密码！');
        }

        // todo 统一验证入参
        if (typeof args.login_password != 'string' || args.login_password.length != 32) {
            return callback(11, null, '缺少参数(login_password)');
        }
        if (typeof args.old_login_password != 'string' || args.old_login_password.length != 32) {
            return callback(11, null, '缺少参数(old_login_password)');
        }

        var sql_find_admin = 'SELECT * FROM deploy_admin WHERE admin_id = ' + session.account_id + ' LIMIT 1';
        uim.db_query(sql_find_admin, function (err, results, fields) {
            if (err) {
                return callback(6, null, '数据库查询出错：' + err);
            }

            if (!results[0]) {
                return callback(6, null, '账户不存在');
            }

            if (results[0]['login_password'] == uim.md5('login_password_' + args.old_login_password)) {
                let new_login_password = uim.md5('login_password_' + args.login_password);
                var sql_update_password = 'UPDATE deploy_admin SET login_password = "' + new_login_password + '" WHERE admin_id = ' + session.account_id + ' LIMIT 1';
                uim.db_query(sql_update_password, function (err, results, fields) {
                    if (err) {
                        return callback(6, null, '数据库查询出错：' + err);
                    }
                    return callback(0, {});

                });
            } else {
                return callback(12, null, '密码错误');
            }

        });
    },

};
